package com.lin.healthmanagement.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig  implements WebMvcConfigurer {
    /**
     * 跨域问题
     * addMapping 拦截的请求
     * allowedOrigins 允许的来源
     * allowedMethods 允许的请求方法
     * allowCredentials 允许携带cookie
     * maxAge 缓存时间
     */
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("http://localhost:5173")
                .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
                .allowCredentials(true)
                .maxAge(2000);
    }
}
